//
//  TRTCLiveRoomEduBoard.m
//  ACLiteAVUISDK
//
//  Created by 冯琰琰 on 2021/4/12.
//

#import "TRTCLiveRoomEduBoard.h"
#import "TEduBoard.h"

@interface TRTCLiveRoomEduBoard ()<TEduBoardDelegate>

@property (nonatomic, copy) NSString *userId;
@property (nonatomic, assign) UInt32 roomId;
@property (nonatomic, assign) int sdkAppId;
@property (nonatomic, copy) NSString *userSig;
@property (nonatomic,strong)TEduBoardController *boardController;
@end


@implementation TRTCLiveRoomEduBoard

- (void)setupSDKWithSDKAppID:(int)sdkAppId userSig:(NSString *)userSig userID:(NSString *)userID{
    self.sdkAppId = sdkAppId;
    self.userSig = userSig;
    self.userId = userID;
}

-(void)startBoardSharingWithRoomID:(int)roomID{
    self.roomId = roomID;
    TEduBoardAuthParam *authParam = [[TEduBoardAuthParam alloc] init];
    authParam.sdkAppId = self.sdkAppId;
    authParam.userId = self.userId;
    authParam.userSig = self.userSig;
    
    // 白板配置
    
    TEduBoardInitParam *initParam = [[TEduBoardInitParam alloc] init];
    initParam.ratio = @"16:9";
    initParam.drawEnable = YES;
    initParam.globalBackgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:1];
    initParam.toolType = TEDU_BOARD_TOOL_TYPE_PEN;
    initParam.brushColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1];
    initParam.brushThin = 100;
    initParam.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1];
    initParam.textSize = 320;
    initParam.textStyle = TEDU_BOARD_TEXT_STYLE_NORMAL;
    
    _boardController = [[TEduBoardController alloc] initWithAuthParam:authParam roomId: self.roomId initParam:initParam];
    [_boardController addDelegate:self];

    
    
//    [_boardController applyFileTranscode:@"https://htsec-demo-1302545507.cos.ap-nanjing.myqcloud.com/20210419/1618824658_607d4dd2340ca.docx" config:<#(TEduBoardTranscodeConfig *)#>];
}

-(void)resetBoard{
    [[self.boardController getBoardRenderView] removeFromSuperview];
    [self.boardController reset];
    [self.boardController removeDelegate:self];
    [self.boardController unInit];
}
// 撤销
-(void)undoBoard{
    [self.boardController undo];
}

// 恢复
-(void)redoBoard{
    [self.boardController redo];
}

-(void)setBoardToolTypePen{
    [self.boardController setToolType:TEDU_BOARD_TOOL_TYPE_PEN];
}

-(void)setBoardToolTypeEraser{
    [self.boardController setToolType:TEDU_BOARD_TOOL_TYPE_ERASER];
}

-(void)addTranscodeFileWithPages:(NSInteger)pages url:(NSString *)url title:(NSString *)title resolution:(NSString *)resolution{
    TEduBoardTranscodeFileResult *result = [[TEduBoardTranscodeFileResult alloc] init];
    result.pages = pages;
    result.resolution = resolution;
    result.url = url;
    result.title = title;
    NSString *filedID = [_boardController addTranscodeFile:result needSwitch:YES];
    DDLogInfo(@"%@",filedID);
}

-(void)onTEBError:(TEduBoardErrorCode)code msg:(NSString *)msg{
    DDLogInfo(@"---------onTEBError -------onTEBError-----msg----%@--------%ld",msg,(long)code);
}
-(void)onTEBWarning:(TEduBoardWarningCode)code msg:(NSString *)msg{
    
}

// 白板窗口获取及显示
-(void)onTEBHistroyDataSyncCompleted{
    TEView *view = [self.boardController getBoardRenderView];
    if ([self canDelegateResponseMethod:@selector(trtcLiveRoomEduBoard:onTEBHistroyDataSyncCompleted:)]) {
        [self.delegate trtcLiveRoomEduBoard:self onTEBHistroyDataSyncCompleted:view];
    }
}

- (void)onTEBAddBoard:(NSArray *)boardIds fileId:(NSString *)fileId {
    
}


- (void)onTEBAddElement:(NSString *)elementId url:(NSString *)url {
    
}


- (void)onTEBAddImageElement:(NSString *)url {
    
}


- (void)onTEBAddImagesFile:(NSString *)fileId {
    
}


- (void)onTEBAddTranscodeFile:(NSString *)fileId {
    DDLogInfo(@"%@-----------onTEBAddTranscodeFile---",fileId);
    
    
    
}


- (void)onTEBAudioStatusChanged:(NSString *)elementId status:(TEduBoardAudioStatus)status progress:(CGFloat)progress duration:(CGFloat)duration {
    
}


- (void)onTEBBackgroundH5StatusChanged:(NSString *)boardId url:(NSString *)url status:(TEduBoardBackgroundH5Status)status {
    
}


- (void)onTEBDeleteBoard:(NSArray *)boardIds fileId:(NSString *)fileId {
    
}


- (void)onTEBDeleteFile:(NSString *)fileId {
    
}


- (void)onTEBFileTranscodeProgress:(TEduBoardTranscodeFileResult *)result path:(NSString *)path errorCode:(NSString *)errorCode errorMsg:(NSString *)errorMsg {
    
}


- (void)onTEBFileUploadProgress:(NSString *)path currentBytes:(int)currentBytes totalBytes:(int)totalBytes uploadSpeed:(int)uploadSpeed percent:(float)percent {
    
}


- (void)onTEBFileUploadStatus:(NSString *)path status:(TEduBoardUploadStatus)status errorCode:(int)errorCode errorMsg:(NSString *)errorMsg {
    
}


- (void)onTEBGotoBoard:(NSString *)boardId fileId:(NSString *)fileId {
    
}


- (void)onTEBGotoStep:(uint32_t)currentStep totalStep:(uint32_t)totalStep {
    
}


- (void)onTEBH5FileStatusChanged:(NSString *)fileId status:(TEduBoardH5FileStatus)status {
    
}


- (void)onTEBH5PPTStatusChanged:(NSString *)fileId status:(TEduBoardH5PPTStatus)status message:(NSString *)message {
    
}


- (void)onTEBImageStatusChanged:(NSString *)boardId url:(NSString *)url status:(TEduBoardImageStatus)status {
    
}


- (void)onTEBInit {
    DDLogInfo(@"---------boardInit -------onTEBInit");
}


- (void)onTEBRectSelected {
    
}


- (void)onTEBRedoStatusChanged:(BOOL)canRedo {
    
}


- (void)onTEBRefresh {
    
}


- (void)onTEBRemoveElement:(NSArray *)elementIds {
    
}


- (void)onTEBSetBackgroundImage:(NSString *)url {
    
}


- (void)onTEBSnapshot:(NSString *)path errorCode:(TEduBoardErrorCode)code errorMsg:(NSString *)msg {
    
}


- (void)onTEBSwitchFile:(NSString *)fileId {
    
}


- (void)onTEBSyncData:(NSString *)data {
    
}


- (void)onTEBUndoStatusChanged:(BOOL)canUndo {
    
}


- (void)onTEBVideoStatusChanged:(NSString *)fileId status:(TEduBoardVideoStatus)status progress:(CGFloat)progress duration:(CGFloat)duration {
    
}

#pragma mark - private method
- (BOOL)canDelegateResponseMethod:(SEL)method {
    return self.delegate && [self.delegate respondsToSelector:method];
}
@end
